package top.frsf.mqttconsumerapp.callback;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

@Slf4j
public class MqttConsumerCallback implements MqttCallback {

    @Override
    public void connectionLost(Throwable throwable) {
        //客户端断开连接后回调
        log.info("与服务器断开连接，可重连");
    }

    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        log.info("接收消息主题：{}，QoS：{}，消息内容：{}，消息retained：{}", topic,
                mqttMessage.getQos(), new String(mqttMessage.getPayload()), mqttMessage.isRetained());
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        //消息发布成功回调
    }
}
